1425A - Arena of Greed - CodeForces Solution


games greedy *1400

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<numeric>
#include<algorithm>
#include<stack>
//sum of sqaures of natural no--- n(n + 1)(2n + 1)/6
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi > vii;
typedef vector<ll> vl;
typedef vector<vi> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl > vll;
const ll mo=(1000000000 + 7);
#define f(i,a,b) for(int i=a;i<b;i++)
#define fm(i,a,b) for(int i=a;i>b;i--)
#define fbe(s) (s.begin(),s.end())
#define fs(p) p.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define it iterator
 int compare(const void* a, const void* b)
{
	const int* x = (int*) a;
	const int* y = (int*) b;
 
	if (*x > *y)
		return 1;
	else if (*x < *y)
		return -1;
 
	return 0;
}

void solve()
{
    ll n;
    cin>>n;
    ll i=0;
    while(n>0)
    {
        if(n==4)
        {
            i+=3;
            break;
        }
        else
        {
            if(n==4)
            {
                i++;
                break;
            }
            if(n%2)
            {
                n=n-1;
                i++;
            }
            else
            {
                if(n%4==0)
                {   
                    n=n-1;
                    i++;
                }
                else
                {
                    i+=n/2;
                    n=n/2;
                }
            }
            if(n==4)
            {
                i++;
                break;
            }
            if(n%2)
            {
                n=n-1;
            }
            else
            {
                if(n%4==0)
                {   
                    n=n-1;
                }
                else
                {
                    n=n/2;
                }
            }
        }
    }
    cout<<i<<endl;
    
}
 
 
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin>>t;
    while(t-->0)
    {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book